import { SECRET_KEY } from "@/constant/key";
import { encryptByBase64DesEcbPkcs7 } from "./crypto";
import { Date } from "./date";
import { AppData } from "./app";

export class Token {
  static get auth() {
    const userData = AppData.userData;
    const text = JSON.stringify({
      account: userData.account || "",
      uid: userData.uid || "",
      login_token: userData.login_token || "",
      openid: userData.openid || "",
      platfrom: "miniprogram",
      package_name: AppData.bundleData.bundleName,
      time: Date.timestamp,
    });
    return encryptByBase64DesEcbPkcs7(text, SECRET_KEY);
  }

  static get cpl() {
    const bundleData = AppData.bundleData;
    const text = JSON.stringify({
      // lng: "",
      // lat: "",
      utm_tid: bundleData.tagId,
      app: bundleData.bundleName,
      ver: bundleData.versionName,
    });
    return encryptByBase64DesEcbPkcs7(text, SECRET_KEY);
  }

  static getSecret(telephone: string, scene = "login"): string {
    const text = JSON.stringify({
      scene,
      telephone,
      platform: "miniprogram",
      package_name: AppData.bundleData.bundleName,
      create_time: Date.timestamp,
    });
    return encryptByBase64DesEcbPkcs7(text, SECRET_KEY);
  }
}
